package ai.zixing.mashibing.new_class.class06;

// https://leetcode.cn/problems/same-tree
public class Code02_SameTree {

    public static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int value) {
            val = value;
        }
    }
    public static boolean isSameTree(TreeNode p, TreeNode q) {
        // 其中有一个为空，一个不为空
        if (p == null ^ q == null) {
            return false;
        }
        // 都为空
        if (p == null && q == null) {
            return true;
        }
        // 都不为空
        return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
